﻿using TopHero;
using UnityEngine;
using Vector2 = TopHero.Vector2;

public class HeroUnityObject : UnityObject
{
    private GameObject _heroObj;

    public float hp;
    public float maxHp;
    public float hpRate;

    public float lightTime;
    public float maxLightTime;
    public float lightTimeRate;

    public float loopNum;

    public override void Link(BaseEntity gameEntity)
    {
        base.Link(gameEntity);
        GameObject prefab = Resources.Load<GameObject>("Hero/lixini");
        _heroObj = Instantiate(prefab);
        _heroObj.transform.parent = transform;
        _heroObj.transform.localPosition = Vector3.zero;
        _heroObj.transform.localScale = Vector3.one * 0.4f;
    }


    private void Update()
    {
        if (_linkedEntity is Hero)
        {
            Hero hero = _linkedEntity as Hero;
            Vector2 position = hero.GetInterpolationPosition();
            transform.position = new Vector3(position.x, position.y);

            hp = hero.GetPropertyValue(PropertyId.HP);
            maxHp = hero.GetPropertyValue(PropertyId.MAX_HP);
            hpRate = hero.GetPropertyValue(PropertyId.HP_RATE);

            lightTime = GameController.Instance.game.world.GetPropertyValue(PropertyId.LIGHT_TIME);
            maxLightTime = GameController.Instance.game.world.GetPropertyValue(PropertyId.MAX_LIGHT_TIME);
            lightTimeRate = GameController.Instance.game.world.GetPropertyValue(PropertyId.LIGHT_TIME_RATE);

            loopNum = GameController.Instance.game.world.GetPropertyValue(PropertyId.LOOP_NUM);
        }
    }
}